package com.spring.mvc.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.spring.mvc.exception.MailNullException;
import com.spring.mvc.mail.MailTemplate;
import com.spring.mvc.mail.SendMail;
import com.spring.mvc.mail.TextMailTemplate;
import com.spring.mvc.pojo.User;

/**
 * 发送邮件工具类
 * @author liujian
 *
 */
public class MailUtil {
	
	private static final Logger logger=LoggerFactory.getLogger(MailUtil.class);
	
	private static final String from="liujian890508@gmail.com";

	/**
	 * 用户注册成功发送激活邮件
	 * @param sendMail
	 * @param to
	 * @param user
	 * @return
	 */
	public static boolean send(SendMail sendMail,User user){
		MailTemplate template=new TextMailTemplate(user.getEmail(),
				from,"spring mail test","spring mail test!  hello world!");
		sendMail.setMailTemplate(template);
		try {
			sendMail.sendMsg();
		} catch (MailNullException e) {
			logger.error("send Mail error",e);
			return false;
		}
		return true;
	}
}
